#ifndef ANALYSISXMLSOURCE_HPP
#define ANALYSISXMLSOURCE_HPP

#include "analysis/AnalysisXML.hpp"
#include "store/struct/Source.hpp"
#include "Utility.hpp"
#include <QString>
#include <QDebug>

// 特化 AnalysisXML<Source> 用于解析内层 XML 文件
template <>
struct AnalysisXML<Source> {
    static Source fromXMLElement(tinyxml2::XMLElement* elem) {
        Source source;
        const char* time  = elem->Attribute("time");
        const char* board = elem->Attribute("board");
        const char* type  = elem->Attribute("type");
        const char* slotsStr = elem->Attribute("slots");

        source.time  = time  ? QString::fromUtf8(time)  : QString();
        source.board = board ? QString::fromUtf8(board) : QString();
        source.type  = parseType(type);

        if (slotsStr) {
            QStringList slotsList = QString(slotsStr).split(",");
            for (const QString& slot : slotsList) {
                bool ok;
                int slotInt = slot.toInt(&ok);
                if (ok) {
                    source.slotsz.append(slotInt);
                } else {
                    qDebug() << "无法将 slot 字符串转换为 int:" << slot;
                }
            }
        }

        return source;
    }
};

#endif // ANALYSISXMLSOURCE_HPP
